#----------------------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(PMTLineShape)

#----------------------------------------------------------------------------
# Specify the C++ standard 
#
set(CMAKE_CXX_STANDARD 17) 
set(CMAKE_CXX_STANDARD_REQUIRED True) 

##----------------------------------------------------------------------------
### Setup ROOT include directories and compile definitions
###
#list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
#find_package(ROOT REQUIRED)
#
## check ROOT version
#if(ROOT_FOUND)
#  STRING(REGEX MATCH "6.*" VERSION6MATCH ${ROOT_VERSION})
#  message(STATUS "version of root: ${ROOT_VERSION}")
#  if(NOT VERSION6MATCH)
#    message(FATAL_ERROR "--> ERROR: ROOT 6 is required but not found")
#  endif()
#endif()

include(${ROOT_USE_FILE})
#MESSAGE(STATUS "ROOT_USE_FILE: ${ROOT_USE_FILE}")

#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
include_directories(${ROOTSYS}/include)

MESSAGE( ${PROJECT_SOURCE_DIR} )
include_directories(${PROJECT_SOURCE_DIR}/source/include)

# Add common libirary
include_directories(${CMAKE_SOURCE_DIR}/source/CommonLib/yaml-cpp/include/yaml-cpp)

file(GLOB_RECURSE sources "${PROJECT_SOURCE_DIR}/*.cc")
file(GLOB_RECURSE headers "${PROJECT_SOURCE_DIR}/*.hh")

#----------------------------------------------------------------------------
# Add the executable, and link it to the ROOT libraries
#
add_executable(LineShape LineShape.cc ${sources} ${headers})
target_link_libraries(LineShape yaml-cpp ${ROOT_LIBRARIES})

#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build My. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.

#file(GLOB_RECURSE Calib_list RELATIVE ${PROJECT_SOURCE_DIR} "./CalibFiles/*")
#foreach(Calib ${Calib_list})
#  MESSAGE( ${Calib} )
#	configure_file(
#		${PROJECT_SOURCE_DIR}/${Calib}
#		${PROJECT_BINARY_DIR}/${Calib}
#		COPYONLY
#		)
#endforeach() 
#
set(SCRIPTS_AND_CARD
CalibFile.yml
lineShapeExtract.py
lhcbStyle.C
)

foreach(script ${SCRIPTS_AND_CARD})
  configure_file(
    ${PROJECT_SOURCE_DIR}/${script}
    ${PROJECT_BINARY_DIR}/${script}
    COPYONLY
  )
endforeach()

#----------------------------------------------------------------------------
# Add program to the project targets
# (this avoids the need of typing the program name after make)
#
add_custom_target(PMTLineShape DEPENDS LineShape)

#----------------------------------------------------------------------------
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
#set(CMAKE_INSTALL_PREFIX ../StarXP-install) 
#install(TARGETS starXP DESTINATION bin)